package com.example.j20240422springtrans.controller;

import com.example.j20240422springtrans.service.LogService;
import com.example.j20240422springtrans.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user2")
public class UserController2 {
    @Autowired
    private UserService userService;

    @Autowired
    private LogService logService;
    @Transactional
    @RequestMapping("/registry")
    public Boolean registry(String userName, String password) {
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return false;
        }
        //插入用户
        userService.registry(userName, password);

        //插入日志
        logService.insertLog(userName, "插入用户");
        return true;
    }
}
